package com.hailiang.ing;

import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.*;

public class LogonServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            doPost(req,resp);
           }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       String uname = req.getParameter("username");

       System.out.println(uname);

        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/login?characterEncoding=utf8","root","root");
            Statement statement = con.createStatement();
            String str = "'uname'";
            ResultSet resultSet = statement.executeQuery("select * from userinfo where username="+str+"");

            if(resultSet.next()){

                System.out.println("该账户不可以使用");

                resp.getWriter().print(0);


            }else{

                System.out.println("该账户可以使用");

                resp.getWriter().print(1);

            }

        } catch (Exception e) {
            e.printStackTrace();
        }



    }
}
